package mock.ab_sd.daointerface;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import org.apache.log4j.Logger;


import com.microsoft.sqlserver.jdbc.SQLServerDataSource;

public class ConnectionFactory {
	public static Connection conn = null;
	public static String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName = ServiceDirectoryDB;integratedSecurity = true;";	
	
	
	public static Connection getConnect() throws ClassCastException, SQLException {			
		
		try{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn = DriverManager.getConnection(connectionUrl,"sa","130891");
			System.out.println("Ket noi thanh cong");
			return conn;
		} catch ( SQLException sqlException ) { 
			JOptionPane.showMessageDialog( null, sqlException.getMessage(), 
					"Database Error", JOptionPane.ERROR_MESSAGE ); 
					
				 System.exit( 1 ); 
				 } 
		catch ( ClassNotFoundException classNotFound ) { 
			JOptionPane.showMessageDialog( null, classNotFound.getMessage(), 
			"Driver Not Found", JOptionPane.ERROR_MESSAGE ); 
			
			System.exit( 1 ); 
			 } 
		
		return null;
	}
	
	public static void main(String[] args) throws SQLException, ClassNotFoundException
	{	      
		ConnectionFactory.getConnect();
	}
}